Skip to content

fix(sidebar): hide badge wrapper when callback returns empty string#2009

Open
mezo-dev wants to merge 5 commits into
unfoldadmin:mainfrom
mezo-dev:fix/empty-badge-on-empty-callback
Open

fix(sidebar): hide badge wrapper when callback returns empty string#2009
mezo-dev wants to merge 5 commits into
unfoldadmin:mainfrom
mezo-dev:fix/empty-badge-on-empty-callback

Conversation

@mezo-dev

@mezo-dev mezo-dev commented Apr 30, 2026

Copy link
Copy Markdown

Fixes #2008 — Empty red badge renders in sidebar when badge callback returns an empty string

Problem

When a sidebar item's badge is configured as a dotted-path string (callback), the red badge wrapper is always rendered — even when the callback returns an empty string. This leaves an empty coloured rectangle in the sidebar.

Root cause

In unfold/sites.py, when item["badge"] is a string, the callback is imported and stored as item["badge_callback"] = lazy(callback)(request), but item["badge"] is left as the original dotted-path string.

In unfold/templates/unfold/helpers/app_list_badge.html, the wrapper guard is:

{% if item.badge %}
    <span class="...">
        {% if item.badge_callback %}{{ item.badge_callback }}{% else %}{{ item.badge }}{% endif %}
    </span>
{% endif %}

item.badge here is the path string (e.g. "myapp.badges.unread_count"), which is always truthy — so the <span> always renders. When the callback resolves to "", the inner content is empty but the wrapper stays, producing the empty box.

Fix

Resolve the lazy callback to a string first and only render the wrapper when the resolved text is non-empty. Behaviour for literal-string badges (no callback) is unchanged.

Screenshots

Before: empty red box next to the menu item when count = 0.

  • image

After: no badge at all when count = 0; badge with text when count > 0.

  • Screenshot 2026-04-30 at 1 41 37 PM

@mgrdcm

mgrdcm commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

@mezo-dev Do you think this also solves your problem? #2084

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty red badge renders in sidebar when badge callback returns an empty string

2 participants